<template>
    <div>
        <van-nav-bar left-text="返回"  right-text="发表" left-arrow title="分享动态" fixed
        @click-right="onClickRight"
        @click-left="onClickLeft">
        </van-nav-bar>
        <div class="content">
            <textarea name="title" id="title" placeholder="分享你的故事..." v-model="message"></textarea>
            <van-uploader name="thumb" v-model="fileList" multiple :max-count="1"/>
        </div>
    </div>
</template>
<script>
export default {
  name: 'DoShare',
  data () {
    return {
      fileList: [],
      message: ''
    }
  },
  methods: {
    getFile (event) {
      // this.file = event.target.files[0];
      console.log(event)
    },
    onClickRight () {
      console.log('this.fileList.length :', this.fileList.length)
      if (this.fileList.length) {
        let formData = new FormData()
        formData.append('SessionID', sessionStorage.sessionid)
        formData.append('mod', 'shaitu')
        formData.append('thumb0', this.fileList[0].file)
        formData.append('userid', sessionStorage.userid)
        formData.append('title', this.message)
        let config = {
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        }
        this.$axios.post('/api/fcreate', formData, config).then((result) => {
          //   console.log(result)
          this.$notify({
            message: '分享成功',
            duration: 1000,
            background: '#1989fa'
          })
          this.$root.$router.go(-1)
        })
      } else {
        this.$notify({ message: '请选择一张图片', duration: 800 })
      }
    },
    onClickLeft () {
      this.$root.$router.go(-1)
    }
  }
}
</script>
<style scoped>
.content{
    padding: 1.5rem;
    margin-top: 50px;
}
textarea{
    border: none;
    width: 100%;
    height: 8rem;
}
</style>
